import {applyMiddleware, compose, createStore} from "redux";
//引入一个帮助我们创建中间件的方法
import createSagaMiddleware from 'redux-saga'
import TodoSagas from './saga'
//引入笔记本
import reducer from "./reducer";
//得到一个中间件
const sagaMiddleware = createSagaMiddleware();

const composeEnhancers =
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
        window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;
const enhancer = composeEnhancers(
    applyMiddleware(sagaMiddleware),
    // other store enhancers if any
);
/**
 * 创建数据的公共存储仓库
 * 相当于图书馆的管理员，还需要Reducers辅助
 * 使用reducer构建初始的数据，然后在创建store的时候会使用一个叫做thunk的中间件
 * @type {Store<S, Action> & Store<S, A> & {dispatch: ThunkDispatch<any, undefined, AnyAction>}}
 */
const store = createStore(reducer, enhancer);
sagaMiddleware.run(TodoSagas)
export default store;